home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 446_01 / DOC / DPBASICS / ODE / ODE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  1.5 KB  |  56 lines

  1.  
  2. #ifndef ode_h_IS_INCLUDED
  3. #define ode_h_IS_INCLUDED
  4.  
  5. #include <ArraysSimple.h>  // defines class Vec(real)
  6.  
  7. class ODESolverUDC;  // forward declaration
  8. class ODESolver
  9. {
  10. protected:
  11.   Vec(real) scratch1;      // scratch vector needed by all algorithms
  12.   ODESolverUDC& eqdef;     // base class reference for user defined function
  13.   void init();
  14. public:
  15.   ODESolver (ODESolverUDC& eqdef);      // construct object
  16.   virtual void advance (Vec(real)& y, real& t, real& dt) =0; // one time step
  17. };
  18.  
  19. class ODESolverUDC
  20. {
  21. public:
  22.   virtual void equation (Vec(real)& f, const Vec(real)& y, real t) =0; //def. f
  23.   virtual int  size () =0;
  24.   virtual void scan (Is is) =0;  // read parameters needed in equation
  25.   virtual void print (Os os) =0;    // write the equation being solved
  26. };
  27.  
  28. // solution algorithms:
  29. class ForwardEulerODE : public ODESolver
  30. {
  31. public:
  32.   ForwardEulerODE (ODESolverUDC& eqdef);
  33.   virtual void advance (Vec(real)& y, real& t, real& dt);
  34. };
  35.  
  36. class RungeKutta4ODE : public ODESolver
  37. {
  38.   Vec(real) scratch2, scratch3;
  39. public:
  40.   RungeKutta4ODE (ODESolverUDC& eqdef);
  41.   virtual void advance (Vec(real)& y, real& t, real& dt);
  42. };
  43.  
  44. // user defined function:
  45. class Oscillator : public ODESolverUDC
  46. {
  47.   real c1,c2,c3,c4,omega;
  48. public:
  49.   Oscillator () {}    // empty constructor
  50.   virtual void equation (Vec(real)& f, const Vec(real)& y, real t);
  51.   virtual int  size () { return 2; }
  52.   virtual void scan (Is is);  // read c1,c2,c3,c4,omega from the screen
  53.   virtual void print (Os);    // write the equation being solved
  54. };
  55. #endif
  56.